home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / bsrc_p1.arc / BTCTL.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-11-30  |  10.7 KB  |  282 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software <no-Inc>                   */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          No-Cost<no-tm> Software.                       */
  7. /*        \ 1011 /                                                          */
  8. /*         ------            KopyRong (K) 1987.  ALL RIGHTS REVERSED.       */
  9. /*                                                                          */
  10. /*                                                                          */
  11. /*               This module was written by Vince Perriello                 */
  12. /*                                                                          */
  13. /*                                                                          */
  14. /*                 BinkleyTerm OMMM Control File Generator                  */
  15. /*                                                                          */
  16. /*                                                                          */
  17. /*   This  software  package is being distributed WITH FULL SOURCE CODE     */
  18. /*   with the  following  conditions:    1)  If  anything awful happens     */
  19. /*   because  you  use    it   (or  don't  use  it),  you  accept  full     */
  20. /*   responsibility;  2) you  don't start making tons of voice calls to     */
  21. /*   the authors to complain or  make  suggestions  about enhancements,     */
  22. /*   useful or otherwise;  3) you  do not reuse this code in commercial     */
  23. /*   products without specific permission to do so  from  the  authors;     */
  24. /*   4) If you find any problems you send  fixes  to  the  authors  for     */
  25. /*   inclusion  in  updates;    5) You find some way  to  express  your     */
  26. /*   appreciation  for  this  method of distribution, either by writing     */
  27. /*   code or  application  notes,  or  just sending along a "Thank You"     */
  28. /*   message.                                                               */
  29. /*                                                                          */
  30. /*   There is  copyrighted  code  in  this product.  We either wrote it     */
  31. /*   ourselves or got  permission  to use it.  Please don't force us to     */
  32. /*   pay a lawyer --  have some respect for our motives and don't abuse     */
  33. /*   this "license".                                                        */
  34. /*                                                                          */
  35. /*                                                                          */
  36. /*--------------------------------------------------------------------------*/
  37.  
  38. #include <stdio.h>
  39. #include <signal.h>
  40. #include <ctype.h>
  41. #include <conio.h>
  42. #include "com.h"
  43. #include "xfer.h"
  44.  
  45. /*--------------------------------------------------------------------------*/
  46. /* BTCTL                                                                    */
  47. /* Parse the BINKLEY.CFG file and write out a BINKLEY.PRM file (for use by  */
  48. /* OMMM) and a MAIL.SYS file (for use by FASTTOSS, SCANMAIL, SIRIUS, etc).  */
  49. /* If the environment variable BINKLEY exists use the path specified for    */
  50. /* ALL input and output files.                                              */
  51. /*--------------------------------------------------------------------------*/
  52.  
  53.  
  54.  
  55. /*--------------------------------------------------------------------------*/
  56. /* MAIL.SYS file structure                                                  */
  57. /*--------------------------------------------------------------------------*/
  58. struct _mail
  59.    begin
  60.       int   pri_node;      /* Our node number                               */
  61.       float fudge;         /* Unknown/unused                                */
  62.       int   rate;          /* Maximum baud rate                             */
  63.       char  mailpath[80];  /* Path for incomming messages                   */
  64.       char  filepath[80];  /* Path for incomming files                      */
  65.       int   pri_net;       /* Our network number                            */
  66.       int   alt_node;      /* Alternate node number (mainly for HOSTS)      */
  67.       int   alt_net;       /* Alternate net number (mainly for HOSTS)       */
  68.    end;
  69. struct _mail mailsys;                /* MAIL.SYS used by SIRIUS  */
  70. struct pointers ctl;                /* where the .CTL stuff is  */
  71.  
  72. char *temp_sysop = NULL;
  73. char *temp_system_name = NULL;
  74. char *temp_hold_area = NULL;
  75. char *ctl_string();
  76.  
  77. int num_addrs = 1;
  78.  
  79. main()
  80. {
  81. char *envptr,*envget();
  82. char *malloc();
  83. FILE *stream;
  84. char temp[80],temp2[80];
  85. char *c;
  86. char *skip_blanks();
  87. int i;
  88.  
  89. /*
  90.  *    Initialize the fields that we care about
  91.  */
  92. ctl.our_zone = 1;                /* Default to Zone 1         */
  93. ctl.version = THIS_CTL_VERSION;            /* Have to set a version     */
  94. temp[0] = '\0';                    /* "null-terminated string"  */
  95. for (i = 0; i < ALIAS_CNT; i++)            /* Zero out all aliases      */
  96.     ctl.alias[i].net = ctl.alias[i].node = 0;
  97. mailsys.pri_node = mailsys.pri_net = mailsys.alt_node = mailsys.alt_net = 0;
  98. for (i = 0; i < 80; i++)            /* Clean out the strings    */
  99.     mailsys.mailpath[i] = mailsys.filepath[i] = '\0';
  100. strcpy (temp, "Binkley.Cfg");
  101. if ((stream = fopen(temp,"r")) == NULL)        /* OK, let's open the file   */
  102.    {   
  103.    envptr = envget("BINKLEY");            /* get path from environment */
  104.    if (envptr != NULL)                /* if there was one,         */
  105.        strcpy(temp,envptr);            /* use it to get things going*/
  106.    strcat(temp,"Binkley.cfg");            /* add in the file name      */
  107.    if ((stream = fopen(temp,"r")) == NULL)        /* OK, let's open the file   */
  108.        errxit("Unable to open BINKLEY.CFG");
  109.    }
  110.  
  111. while((fgets(temp,79,stream)) != NULL)        /* Now we parse the file ... */
  112.     {
  113.     c = temp;                /* Check out the first char  */
  114.     if ((*c == '%') || (*c == ';'))        /* See if it's a comment line*/
  115.         continue;
  116.  
  117.     i = strlen(temp);            /* how long this line is     */
  118.     if (i < 6)                /* treat something SHORT     */
  119.         continue;            /* as a comment line         */
  120.  
  121.     c = &temp[--i];                /* point at last character   */
  122.     if (*c == '\n')                /* if it's a newline,        */
  123.         *c = '\0';            /* strip it off              */
  124.  
  125.  
  126.     if (strnicmp(temp,"zone",4) == 0)    /* Zone we are in            */
  127.         {
  128.         c = skip_blanks(&temp[4]);
  129.         ctl.our_zone = atoi(c);
  130.         if (!ctl.our_zone)        /* if we didn't find a zone  */
  131.             {
  132.             sprintf(temp2,"Illegal zone: %s\n", &temp[4]);
  133.             errxit(temp2);
  134.             }
  135.         continue;
  136.         }
  137.  
  138.     if (strnicmp(temp,"point",5) == 0)    /* if this is my point name  */
  139.         {
  140.         c = skip_blanks(&temp[5]);
  141.         sscanf(c,"%d/%d",&ctl.alias[0].net,&ctl.alias[0].node);
  142.         mailsys.pri_net = ctl.alias[0].net;
  143.         mailsys.pri_node = ctl.alias[0].node;
  144.         continue;
  145.         }
  146.  
  147.     if (strnicmp(temp,"aka",3) == 0)    /* if this is an AKA name  */
  148.         {
  149.         c = skip_blanks(&temp[3]);
  150.         sscanf(c,"%d/%d",&ctl.alias[num_addrs].net,&ctl.alias[num_addrs].node);
  151.       if (num_addrs == 1)
  152.          {
  153.            mailsys.pri_net = ctl.alias[1].net;
  154.            mailsys.pri_node = ctl.alias[1].node;
  155.          }
  156.       ++num_addrs;
  157.         continue;
  158.         }
  159.  
  160.     if (strnicmp(temp,"boss",4) == 0)    /* If this is my boss name   */
  161.         {
  162.         c = skip_blanks(&temp[4]);
  163.         continue;
  164.         }
  165.  
  166.     if (strnicmp(temp,"netfile",7) == 0)    /* inbound file area         */
  167.         {
  168.         c = skip_blanks(&temp[7]);
  169.         strcpy(mailsys.filepath,c);    /* copy it                   */
  170.         continue;
  171.         }
  172.  
  173.     if (strnicmp(temp,"netmail",7) == 0)    /* matrix message area       */
  174.         {
  175.         c = skip_blanks(&temp[7]);
  176.         strcpy(mailsys.mailpath,c);    /* copy it                   */
  177.         continue;
  178.         }
  179.  
  180.     if (strnicmp(temp,"system",6) == 0)    /* if this is system name    */
  181.         {
  182.         temp_system_name = ctl_string(&temp[6]);
  183.         continue;
  184.         }
  185.  
  186.     if (strnicmp(temp,"sysop",5) == 0)    /* if this is my name        */
  187.         {
  188.         temp_sysop = ctl_string(&temp[5]);
  189.         continue;
  190.         }
  191.  
  192.     if (strnicmp(temp,"hold",4) == 0)    /* matrix hold area          */
  193.         {
  194.         temp_hold_area = ctl_string(&temp[4]);
  195.         continue;
  196.         }
  197.  
  198.     if (strnicmp(temp,"nodelist",8) == 0)    /* if a nodelist spec,       */
  199.         {
  200.         ctl.net_info = ctl_string(&temp[8]);
  201.         continue;
  202.         }
  203.     }
  204. fclose(stream);                    /* close input file          */
  205. /*
  206.  *    Okay, we have the nodelist data from the BINKLEY.CFG file.
  207.  *    Now write it into a BINKLEY.PRM file.
  208.  */
  209. if (ctl.alias[0].net == 0)            /* Got to have at least our  */
  210.     errxit("No Network Address was entered");/* own address!!            */
  211. if (envptr != NULL)                /* If there was a BINKLEY,   */
  212.     strcpy(temp,envptr);            /* use it here too           */
  213. else
  214.    temp[0] = '\0';
  215. strcat(temp,"Binkley.Prm");            /* add in the file name      */
  216. if ((stream = fopen(temp,"wb")) == NULL)    /* OK, let's open the file   */
  217.     errxit("Unable to open BINKLEY.PRM");
  218. if (fwrite(&ctl,sizeof(ctl),1,stream) != 1)    /* Try to write the data out */
  219.     errxit("Could not write control file data to BINKLEY.PRM");
  220. fclose(stream);                    /* close output file         */
  221. printf("Control file successfully written\n");    /* Notify user of success    */
  222.  
  223. if (envptr != NULL)                /* If there was a BINKLEY,   */
  224.     strcpy(temp,envptr);            /* use it here too           */
  225. else
  226.    temp[0] = '\0';
  227. strcat(temp,"Mail.Sys");            /* add in the file name      */
  228. if ((stream = fopen(temp,"wb")) == NULL)    /* OK, let's open the file   */
  229.     errxit("Could not open MAIL.SYS");    /* no file, no work to do    */
  230. if (fwrite(&mailsys,sizeof(mailsys),1,stream) != 1)
  231.     errxit("Unable to write data to MAIL.SYS");/* Try to write the data out */
  232. fclose(stream);                    /* close output file         */
  233. printf("MAIL.SYS file successfully written\n");    /* Notify user of success    */
  234. }
  235.  
  236. errxit(error)
  237. char *error;
  238. {
  239. printf("\r\n%s\n",error);
  240. exit(0);
  241. }
  242.  
  243. char *ctl_string(source)            /* malloc & copy to ctl      */
  244. char *source;
  245. {
  246. char *malloc();
  247. char *dest, *c;
  248. c = skip_blanks(source);            /* get over the blanks       */
  249. dest = malloc(strlen(c)+1);            /* allocate space for string */
  250. strcpy(dest,c);                    /* copy the stuff over       */
  251. return(dest);                    /* and return the address    */
  252. }
  253.  
  254. char *skip_blanks(string)
  255. char *string;
  256. {
  257. while (*string == ' ' || *string == '\t')
  258.     ++string;
  259. return(string);
  260. }
  261.  
  262. /*
  263.  *    envget - routine to find environment variables, copy them
  264.  *    into a local string, then pass the string back. It's the caller's
  265.  *    responsibility to handle re-entrancy problems. Usually the result
  266.  *    of this operation is transient.
  267.  */
  268. static char env_value[80];
  269.  
  270. char *envget(string)
  271. char *string;
  272. {
  273. char *dev,*getenv();
  274. if ((dev = getenv(string)) != NULL)
  275.     {
  276.     strcpy(env_value,dev);
  277.     return(env_value);
  278.     }
  279. env_value[0] = '\0';            /* put nothing there */
  280. return(env_value);            /* if we got nothing give nothing */
  281. }
  282.